<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="page" tagdir="/WEB-INF/tags"%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Post List</title>
    <link rel="stylesheet" type="text/css" href="<c:url value="/CSS/post/postList.css"/>"/>
  </head>
  <body>
    <div class="container">
      <jsp:include page="/WEB-INF/JSP/head.jsp"/>
      <div class="body">
        <div class="topic-title">
          <a href="<c:url value="${sessionScope.topicPathURL}"/>">&lt;==</a>&nbsp;Topic - ${topic.title}
        </div>
        <div class="topic-fields">
          <div class="left">
            <div class="topic-field">Author: ${topic.user.userName}</div>
            <div class="topic-field">Views: ${topic.views}</div>
            <div class="topic-field">Replies: ${topic.posts.size()}</div>
            <div class="topic-field">Digest: ${(topic.digest == 0)? 'No': 'Yes'}</div>
            <div class="topic-field">CreatedTime: ${fn:substring(topic.createTime, 0, 19)}</div>
            <div class="topic-field">Board: ${topic.board.boardName}</div>
          </div>
          <div class="right">
            <div class="topic-field">
              <textarea readonly="readonly">Content: ${topic.content}</textarea>
            </div>
          </div>
        </div>
        <div class="post-list">
          <div class="caption">
            <div class="title">Replied Posts</div>
            <div class="add-post">
              <c:choose>
                <c:when test="${sessionScope.sessionUser != null}">
                  <a href="javascript:" onclick="javascript:openWindow('<c:url value="/post/addPost-${topic.topicId}"/>', 600, 320);">Add Post</a>
                </c:when>
                <c:otherwise>
                  <span class="grey">Add Post</span>
                </c:otherwise>
              </c:choose>
            </div>
          </div>
          <div class="tr1">
            <div class="td1">Title</div>
            <div class="td2">Author</div>
            <div class="td3">CreatedTime</div>
            <div class="td4">Update</div>
            <div class="td5">Delete</div>
          </div>
        </div>
        <c:if test="${pagedPosts.list != null}">
          <c:forEach var="post" items="${pagedPosts.list}" varStatus="status">
            <div class="tr2" id="row_${status.index}"
              onmouseover="toggleBackground('row_${status.index}', 0)"
              onmouseout="toggleBackground('row_${status.index}', 1)">
              <div class="td1"><a href="javascript:" onclick="javascript:openWindow('<c:url value="/post/postDetail-${post.postId}"/>', 600, 320);">${post.title}</a></div>
              <div class="td2">${post.user.userName}</div>
              <div class="td3">${fn:substring(post.createTime, 0, 19)}</div>
              <div class="td4">
                <c:choose>
                  <c:when test="${sessionScope.sessionUser != null && sessionScope.sessionUser.userId == post.user.userId}">
                    <a href="javascript:" onclick="javascript:openWindow('<c:url value="/post/updatePost-${post.postId}"/>', 600, 320)">Update</a>
                  </c:when>
                  <c:otherwise>
                    <span class="grey">Update</span>
                  </c:otherwise>
                </c:choose>
              </div>
              <div class="td5">
                <c:choose>
                  <c:when test="${boardManager != null || (sessionScope.sessionUser != null && sessionScope.sessionUser.userId == post.user.userId)}">
                    <a href="javascript:" onclick="javascript:openWindow('<c:url value="/post/deletePost-${post.postId}"/>', 600, 320)">Delete</a>
                  </c:when>
                  <c:otherwise>
                    <span class="grey">Delete</span>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
          </c:forEach>
        </c:if>
        <div id="page">
          <page:PageBar pageURL="/post/postList-${topicId}" pageAttrKey="pagedPosts"></page:PageBar>
        </div>
      </div>
      <jsp:include page="/WEB-INF/JSP/foot.jsp"/>
    </div>
    <script type="text/javascript" src="<c:url value="/JS/jquery-1.7.2.min.js"/>"></script>
    <script type="text/javascript" src="<c:url value="/JS/jcommon.js"/>"></script>
  </body>
</html>